<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>junglego: neuron.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">junglego
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">neuron.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="neuron_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="neuron_8hpp.html">neuron.hpp</a>&quot;</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 
<a name="l00004"></a><a class="code" href="class_neuron.html#a823487d01615fadb8ac19a2768dd9d96">00004</a> <a class="code" href="class_neuron.html#a823487d01615fadb8ac19a2768dd9d96">Neuron::Neuron</a>() {
<a name="l00005"></a>00005     <a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a> = 0;
<a name="l00006"></a>00006     <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a> = 0;
<a name="l00007"></a>00007     <a class="code" href="class_neuron.html#ad5a9673fbe120c0f6f517f5161e5c440">m_threshold</a> = 0;
<a name="l00008"></a>00008     <a class="code" href="class_neuron.html#ae679bea3dee256f4c6e41a18bcf58b82">m_state</a> = 0;
<a name="l00009"></a>00009 }
<a name="l00010"></a>00010 
<a name="l00011"></a><a class="code" href="class_neuron.html#a94a250ce7e167760e593979b899745b1">00011</a> <a class="code" href="class_neuron.html#a94a250ce7e167760e593979b899745b1">Neuron::~Neuron</a>() {
<a name="l00012"></a>00012     <span class="keyword">delete</span>[] <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a>;
<a name="l00013"></a>00013 }
<a name="l00014"></a>00014 
<a name="l00015"></a><a class="code" href="class_neuron.html#a471ac0d115eb2c16b3a4278f9d8f88e5">00015</a> <span class="keywordtype">void</span> <a class="code" href="class_neuron.html#a471ac0d115eb2c16b3a4278f9d8f88e5">Neuron::init</a> (<a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> nConn, <a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> threshold) {
<a name="l00016"></a>00016     <a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a> = nConn;
<a name="l00017"></a>00017     <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a> = <span class="keyword">new</span> <a class="code" href="structconnection.html">connection</a> [<a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a>];
<a name="l00018"></a>00018     <a class="code" href="class_neuron.html#ad5a9673fbe120c0f6f517f5161e5c440">m_threshold</a> = threshold;
<a name="l00019"></a>00019 }
<a name="l00020"></a>00020 
<a name="l00021"></a><a class="code" href="class_neuron.html#a6ee756ddc01b4c332ebfb1a19449453f">00021</a> <span class="keywordtype">void</span> <a class="code" href="class_neuron.html#a0bcd9db8844e35e22268568286742117">Neuron::setState</a> (<span class="keywordtype">float</span> state) {
<a name="l00022"></a>00022     <a class="code" href="class_neuron.html#ae679bea3dee256f4c6e41a18bcf58b82">m_state</a> = state;
<a name="l00023"></a>00023 }
<a name="l00024"></a>00024 
<a name="l00025"></a><a class="code" href="class_neuron.html#ab2734b21c9d748fe8c67a41c401e041a">00025</a> <span class="keywordtype">float</span> <a class="code" href="class_neuron.html#ab2734b21c9d748fe8c67a41c401e041a">Neuron::getState</a> () {
<a name="l00026"></a>00026     <span class="keywordflow">return</span> <a class="code" href="class_neuron.html#ae679bea3dee256f4c6e41a18bcf58b82">m_state</a>;
<a name="l00027"></a>00027 }
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="class_neuron.html#abcc93d2ce3bf6ade4a50034737d29bda">00029</a> <span class="keywordtype">void</span> <a class="code" href="class_neuron.html#abcc93d2ce3bf6ade4a50034737d29bda">Neuron::copy</a> (<a class="code" href="class_neuron.html">Neuron</a> * source) {
<a name="l00030"></a>00030     <span class="keywordflow">if</span> (<a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a> != source-&gt;<a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a>) {
<a name="l00031"></a>00031         <span class="keyword">delete</span>[] <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a>;
<a name="l00032"></a>00032         <a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a> = source-&gt;<a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a>;
<a name="l00033"></a>00033         <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a> = <span class="keyword">new</span> <a class="code" href="structconnection.html">connection</a> [source-&gt;<a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a>];
<a name="l00034"></a>00034     }
<a name="l00035"></a>00035     <span class="keywordflow">for</span> (<a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> i = 0; i &lt; <a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a>; i++) {
<a name="l00036"></a>00036         <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a>[i] = source-&gt;<a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a>[i];
<a name="l00037"></a>00037     }
<a name="l00038"></a>00038 }
<a name="l00039"></a><a class="code" href="class_neuron.html#ac231bb1f90ee544bc541c584457e4ac2">00039</a> <span class="keywordtype">void</span> <a class="code" href="class_neuron.html#ac231bb1f90ee544bc541c584457e4ac2">Neuron::mutate</a> (<span class="keywordtype">int</span> rate) {
<a name="l00040"></a>00040     <a class="code" href="class_neuron.html#ad5a9673fbe120c0f6f517f5161e5c440">m_threshold</a> += rand() % rate - rate/2;
<a name="l00041"></a>00041     <span class="keywordflow">for</span> (<a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> i = 0; i &lt; <a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a>; i++) {
<a name="l00042"></a>00042         <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a>[i].<a class="code" href="structconnection.html#a1eb6b0e42f4f3721f21b15a7730403ca">weight</a> += rand() % rate - rate/2;
<a name="l00043"></a>00043     }
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 
<a name="l00046"></a><a class="code" href="class_neuron.html#ada09a088efc0036ee18261c09ab57c8e">00046</a> <span class="keywordtype">void</span> <a class="code" href="class_neuron.html#ada09a088efc0036ee18261c09ab57c8e">Neuron::compute</a>(){
<a name="l00047"></a>00047     <span class="keywordflow">for</span> (<a class="code" href="types_8hpp.html#a91ad9478d81a7aaf2593e8d9c3d06a14">uint</a> i=0; i&lt;<a class="code" href="class_neuron.html#ac33cc5f02847c1ea2db58262bf26b016">m_nConn</a>; i++){
<a name="l00048"></a>00048         <a class="code" href="class_neuron.html#ae679bea3dee256f4c6e41a18bcf58b82">m_state</a> += <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a>[i].<a class="code" href="structconnection.html#a1d859933a73cb920509d054135d9610d">pNeuron</a>-&gt;<a class="code" href="class_neuron.html#ab2734b21c9d748fe8c67a41c401e041a">getState</a>() * <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a>[i].<a class="code" href="structconnection.html#a1eb6b0e42f4f3721f21b15a7730403ca">weight</a>;
<a name="l00049"></a>00049     }
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051 
<a name="l00052"></a><a class="code" href="class_neuron.html#a0cab4dd80848201e0f10fae42b1d8655">00052</a> <a class="code" href="structconnection.html">connection</a> * <a class="code" href="class_neuron.html#a0cab4dd80848201e0f10fae42b1d8655">Neuron::getConnections</a>(){
<a name="l00053"></a>00053     <span class="keywordflow">return</span> <a class="code" href="class_neuron.html#af6c0c80c1b8e86b392d84b8371d10f23">m_connections</a>;
<a name="l00054"></a>00054 }
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 20 2012 21:57:14 for junglego by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
